/**
 * 功能描述
 */
define(function (require, exports, module) {
	var Component = require("grid");
	var aw = require("ajaxwrapper");
	var proctrgrid = require("../constant/fetchProperties");
	var Dialog = require("dialog");
	var store =require("store");
	var activeUser = store.get("user");
	var Form = require("form");
	var gridqxEvents = require("../handler/gridqxEvents");
	var gridgsEvents = require("../handler/gridgsEvents");
	var gridtkEvents = require("../handler/gridtkEvents");
	var gridbbEvents = require("../handler/gridbbEvents");
	var gridmxEvents = require("../handler/gridmxEvents");
    var instance = {
        initComponent: function (params, widget) {
            var grid = new Component({
            	parentNode : ".J-grid",	
            	url : "api/welfareconsumptioncoupon/querywelfare",
//            	autoRender : false,
				params : function(){
					var subnav = widget.get("subnav");
					var obj = {
                			"servicePoint" : subnav.getValue("servicePoint"),
                			"status" : subnav.getValue("status"),
                			"grantDate" : subnav.getValue("startDate").start,
                			"grantDateEnd" : subnav.getValue("startDate").end,
                			fetchProperties : proctrgrid.fetchProperties
                	};
	    			return obj;
				},
				model : {
				 columns  : [{
					 name : "cardNo",//
					 label : "卡号",
					 params: function(){
						 widget.get("grid").load("cardNo");
					 }
				 },{
					 name : "travelContract.member.personalInfo.name",
					 label : "会员",
				 },{
					 name : "travelContract.memberCertificates",
					 label : "证件号",
				 },{
					 name : "travelContract.member.personalInfo.mobilePhone",
					 label : "联系电话",
				 },{
					 name : "balance",
					 label : "余额(元)",
				 },{
					 name : "grantDate",
					 label : "发放日期",
					 format : "date",
				 },{
					 name : "status.value",
					 label : "状态",
				 },{
						name:"operate",
						label:"操作",
						format:"button",
						formatparams:[{
							id:"set",
							icon:"icon-edit",
							text:"取现",
							show: function(value,data){
        						if(data.status.key == "Effective"){
        							return true;
        						}else{
        							return false;
        						}
        					},
							handler:function(index,data,rowEle){
								gridqxEvents.gridQx(data,widget);
							}
						},{
							id:"gs",
							icon:"icon-edit",
							text:"挂失",
							show: function(value,data){
        						if(data.status.key == "Lose" || data.status.key == "Returned"){
        							return false;
        						}else{
        							return true;
        						}
	        				},
							handler:function(index,data,rowEle){
								gridgsEvents.gridGs(data,widget);
							}
						},{
							id:"tk",
							icon:"icon-edit",
							text:"退卡",
							show: function(value,data){
        						if(data.status.key == "Lose" || data.status.key == "Returned"){
        							return false;
        						}else{
        							return true;
        						}
	        				},
							handler:function(index,data,rowEle){
								gridtkEvents.gridTk(data,widget);
							}
						},{
							id:"bb",
							icon:"icon-edit",
							text:"补办",
							show: function(value,data){
        						if(data.status.key == "Lose"){
        							return true;
        						}else{
        							return false;
        						}
	        				},
							handler:function(index,data,rowEle){
								gridbbEvents.gridBb(data,widget);
							}
						},{
							id:"detail",
							icon:"icon-edit",
							text:"明细",
							handler:function(index,data,rowEle){
//	    						widget.get("detailgrid").refresh();
								widget.show([".J-detailgrid"]).hide([".J-grid"]);
	    						widget.get("subnav").hide(["search","add","servicePoint","startDate","status"]).show(["return","operateDate"]);
								widget.get("subnav").setTitle("消费券明细");
								gridmxEvents.gridMx(data,widget);
	    						widget.get("detailgrid").refresh();
							}
						}]
				 }]
				}
            });
            widget.set("grid", grid);
        }
    };
    module.exports = instance;
});
